﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Input;
using System.Windows.Threading;
using Client.App.ViewModels.Interfaces;
using Core.Mvvm.Commands;
using Core.Mvvm.ViewModels;
using Multiprocessing.Core.Algorithm;

namespace Client.App.ViewModels.Implementations
{
    public abstract class BaseTestViewModel : BaseViewModel, ITestViewModel
    {
        #region Fields

        private IAlgorithm _algorithm;
        private ICommand _startAnalyzeCommand;
        private bool _isAnalyzing;

        #endregion

        #region Properties

        public IAlgorithm Algorithm 
        {
            get { return _algorithm; }
            set { SetProperty(ref _algorithm, value, () => Algorithm); }
        }

        public ICommand StartAnalyzeCommand
        {
            get
            {
                return _startAnalyzeCommand ??
                       (_startAnalyzeCommand = new SimpleCommand(OnStartAnalyze, CanStartAnalyze));
            }
        }

        public bool IsAnalyzing 
        {
            get { return _isAnalyzing; }
            set { SetProperty(ref _isAnalyzing, value, () => IsAnalyzing); }
        }


        protected virtual bool CanStartAnalyze()
        {
            return this.Algorithm != null;
        }

        protected virtual void OnStartAnalyze()
        {
            OnAnalyze();
        }

        protected abstract void OnAnalyze();

        #endregion

        #region Constructors

        protected BaseTestViewModel(Dispatcher dispatcher) 
            : base(dispatcher)
        {
        }

        #endregion
    }
}
